package hn.cch.framework.database;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class MySQLDemo {

    private static final Logger logger = LoggerFactory.getLogger(PostgreSQLDemo.class);

    @Test
    public void test() {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://192.168.10.134:3306/demo?useSSL=false";
        String user = "root";
        String password = "chench";

        Connection connection = null;
        PreparedStatement prepareStatement = null;

        try {
            Class.forName(driver);
            connection = DriverManager.getConnection(url, user, password);

            String sql = "INSERT INTO `demo`.`test` (`id`, `no`) VALUES (?, ?)";
            prepareStatement = connection.prepareStatement(sql);

            // int column = prepareStatement.executeUpdate();
            // System.out.println("column:" + column);

        } catch (Exception e) {
            System.out.println("oracleJdbc:" + e.getMessage());
        } finally {
            try {
                if (prepareStatement != null
                        && prepareStatement.isClosed()) {
                    prepareStatement.close();
                }

                if (connection != null
                        && connection.isClosed()) {
                    connection.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }

}

